package gui;

import java.awt.GridLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import components.Node;

import languages.Language;

public class TabInsertPointDegrees extends JPanel implements ActionListener{

	private Language lang;
	
	private JButton add,clear;
	private JTextField lattitude,longtitude;
	private JTextField four;
	
	private Window parent;
	
	public TabInsertPointDegrees(Language lang, Window parent) {
		this.lang = lang;
		this.parent = parent;
		
		this.setLayout(new GridLayout(4,2));
		
		createGUI();
	}

	private void createGUI() {
		
		this.add(new JLabel(lang.tiPMLat()));
		lattitude = new JTextField();
		this.add(lattitude);
		
		this.add(new JLabel(lang.tiPMLon()));
		longtitude = new JTextField();
		this.add(longtitude);
		
//		this.add(new JLabel(lang.tiPM4()));
		four = new JTextField();
//		this.add(four);
		
		add = new JButton(lang.tiAdd());
		add.setActionCommand("ADD");
		add.addActionListener(this);
		this.add(add);
		
		clear = new JButton(lang.tiClear());
		clear.setActionCommand("CLEAR");
		clear.addActionListener(this);
		this.add(clear);
		
	}

	public void createPoint(){
		Node newNode = new Node();
		float lon = Float.parseFloat(this.longtitude.getText());
		float lat = Float.parseFloat(this.lattitude.getText());
		
		newNode.setLongtitude(lon);
		newNode.setLattitude(lat);
		
		this.parent.getNodeList().getNodes().add(newNode);
		
		this.parent.getNodeLayer().addNode(newNode);
	}
	
	public void actionPerformed(ActionEvent e) {
		String command = e.getActionCommand();
		
		System.out.println(command);
		
		if("ADD".equals(command)){
			
		}
		else if("CLEAR".equals(command)){
			lattitude.setText("");
			longtitude.setText("");
			four.setText("");
		}
	}

}
